layui.use(['laydate','form','table','layer','laytpl','gcate'], function(){
	var laydate = layui.laydate,form = layui.form,table = layui.table,layer = layui.layer,laytpl = layui.laytpl,gcate = layui.gcate;
	/*开始时间*/
	laydate.render({
	  	elem: '#start' //指定元素
	});
	/*结束时间*/
	laydate.render({
	  	elem: '#end' //指定元素
	});
	/*@初始化table*/
	var tableObj = table.render({
	    elem: '#table-list',
	    url: '/staff/goods/index', //数据接口
	    page: false, //开启分页
	    limits: false,
	    cols: [[ //表头
	    	{field: 'goods_name', title: '产品名称'},
	    	{field: 'number', title: '销售数量'},
	    	{field: 'unit', title: '单位'},
	    	{field: 'goods_money', title: '销售总额（元）'},
	    	{field: 'cost_money', title: '销售总成本（元）'},
	    	{field: 'refund_money', title: '退款总额（元）'},
	    	{field: 'recal_money', title: '召回总额（元)'},
	    	{field: 'profit_money', title: '销售总盈利（元）'},
	    	{field: 'profit_t_money', title: '盈利总提成（元）'},
	    	{field: 'turnover_t_money', title: '营业额总提成（元）'},
	    ]],
	    parseData: function(res){
	    	var all = res.data.count
	    	res.data = res.data.list
	    	/*@统计*/
			var getTpl_2 = order_count.innerHTML;
			var count = document.getElementById('order-count');
			laytpl(getTpl_2).render(all[0], function(html){
				count.innerHTML = html;
			});
	    },
	});
	/*@查询*/
	form.on('submit(search)',function(data){

		if(data.field.start != '' && data.field.end != ''){
			var startDate = new Date(data.field.start).getTime();
			var endDate = new Date(data.field.end).getTime();
			if(startDate > endDate){
				layer.msg('开始时间不能大于结束时间',{icon: 2})
				return false
			}
		}
		/*重载表格数据*/
		tableObj.reload({
			page: {
                page: 1 //重新从第 1 页开始
            },
            where: data.field
        });
        return false
	})
	/*@产品分类*/
	gcate.form.g_cate('select', '/staff/goods/sun_cate')
});